package net.xyuu;

import java.sql.Connection;
import java.sql.SQLException;

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.service.ServiceRegistry;

public class JdbcConnectionAccessImpl implements JdbcConnectionAccess {

	private static final long serialVersionUID = 1L;

	private final ConnectionProvider connectionProvider;

	public JdbcConnectionAccessImpl(ConnectionProvider connectionProvider) {
		this.connectionProvider = connectionProvider;
	}

	public JdbcConnectionAccessImpl(ServiceRegistry serviceRegistry) {
		this(serviceRegistry.getService(ConnectionProvider.class));
	}

	@Override
	public Connection obtainConnection() throws SQLException {
		return connectionProvider.getConnection();
	}

	@Override
	public void releaseConnection(Connection connection) throws SQLException {
		connectionProvider.closeConnection(connection);
	}

	@Override
	public boolean supportsAggressiveRelease() {
		return connectionProvider.supportsAggressiveRelease();
	}
}
